package cn.kginglam.dynamic_excel.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.kginglam.dynamic_excel.common.utils.*;
import cn.kginglam.dynamic_excel.mapper.StudentInfoMapper;
import cn.kginglam.dynamic_excel.model.entity.StudentInfo;
import cn.kginglam.dynamic_excel.model.excel.StudentInfoImportModule;
import cn.kginglam.dynamic_excel.service.StudentInfoService;
import cn.kginglam.dynamic_excel.strategy.constant.ImportExcel2DatabaseEnum;
import cn.kginglam.dynamic_excel.strategy.factory.ImportExcel2DatabaseStrategyFactory;
import cn.kginglam.dynamic_excel.strategy.param.ImportExcel2DatabaseParam;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

/**
 * <p>
 * 开放学员信息表 服务实现类
 * </p>
 *
 * @author Lam
 * @since 2021-09-02
 */
@Service
public class StudentInfoServiceImpl extends ServiceImpl<StudentInfoMapper, StudentInfo> implements StudentInfoService {

    @Autowired
    private ImportExcel2DatabaseParam importExcel2DatabaseParam;


    @Override
    public void importExcel2Database(List<StudentInfoImportModule> studentInfoImportModuleList) {

        ImportExcel2DatabaseStrategyFactory
                .getInstantiation(ImportExcel2DatabaseEnum.STUDENT_INFO_IMPORT_EXCEL_2_DATABASE.getStrategyKey(), importExcel2DatabaseParam)
                .execute(studentInfoImportModuleList);

    }

    @Override
    public void batchSave(List<StudentInfo> studentInfoList) {
        if (CollectionUtil.isEmpty(studentInfoList)) return;

        this.baseMapper.batchSave(studentInfoList);
    }

    @Override
    public List<String> listPhoneByPhoneList(List<String> phoneList) {
        return baseMapper.listPhoneByPhoneList(phoneList);
    }

    @Override
    public List<String> listCardNoByCardNoList(List<String> cardNoList) {
        return baseMapper.listCardNoByCardNoList(cardNoList);
    }
}
